package Aleehot100;

import C017.main;

import java.util.*;

/**
 * ClassName: c061
 * Package: Aleehot100
 * Description: 131. 分割回文串 前置题目 ： 获取一个字符串的全部的回文子串
 *
 * @Author BCXJ
 * @Create 2025/8/10 22:10
 * @Version 1.0
 * @Since 1.0
 */
public class c061_1 {
    public static void main(String[] args) {
        String str = "123321";
        System.out.println(problem1(str));
    }


    static boolean[][] flag = new boolean[16][16];
    static int len;
    static Set<String> res;
    static String str;

    /**
     * 返回s中的全部回文串
     * @param s
     * @return
     */
    public static Set<String> problem1(String s) {
        for (boolean[] booleans : flag) {
            Arrays.fill(booleans, false);
        }
        str = s;
        res = new HashSet<>();
        len = s.length();
        for (int i = 0; i < len; i++)   {
            for (int j = i; j < len; j++) {
                if(!flag[i][j]) { // 没有判断过的才进
                    isReverse(s, i, j);
                }
            }
        }

        return res;
    }

    private static void isReverse(String s, int i1, int i2) {
        char[] arr = s.substring(i1, i2 + 1).toCharArray();

        for (int l = 0 , r = arr.length - 1; l < r; l++, r--) {
            if(arr[l] != arr[r]) {
                return; // 默认为false
            }
        }
        System.out.println(s.substring(i1, i2 + 1));
        while((i1 >= 0 && i1 < len) && (i2 >= 0 && i2 < len) && (i1 <= i2)) {
            flag[i1][i2] = true;
            System.out.println(str.substring(i1, i2 + 1));
            res.add(str.substring(i1, i2 + 1));
            i1 ++;
            i2 --;
        }
        return;
    }

}
